<?php
if(!$session->isModerator())
{
	 header("Location: ../index.php");
}
else{ ?>
	<div id="form_container" style="width:916px; margin:10px 20px;">
		<div id="title_container">
			<div id="title">
				<p>Update Requests</p>
			</div>
		</div>
		<div id="form_content" style="width:916px; padding:0;">
		<?php 
            $result = mysql_query("SELECT * FROM update_queue ORDER BY timestamp DESC");
            $total_results = mysql_num_rows($result);
            if(!$result || ($total_results < 0)){
            echo "<p>Error displaying info</p>";
            return;
            }
            if($total_results == 0){
                echo "<p>There are no update</p>";
                return;
            }
            else 
            { ?>
        <table id="updateTable" cellpadding="0" cellspacing="0">
            <thead style="visibility:hidden">
                <th width="20px"></th>
                <th width="200px"></th>
                <th width="500px"></th>
                <th width="150px"></th>
                <th></th>
            </thead>
            <tbody>
			<?php for($i = 0; $i < $total_results; $i++)
            {
                // make sure that PHP doesn't try to show results that don't exist
                if ($i == $total_results) { break; }
                // echo out the contents of each row into update
				$modAction = mysql_result($result, $i, 'modAction');
                $time_stamp = strtotime(mysql_result($result, $i, 'timestamp'));
                $orgID = mysql_result($result, $i, 'orgID');
                $id = mysql_result($result, $i, 'id');
                $orgInfo = mysql_query("SELECT * FROM organizations WHERE orgID='$orgID'");
                $orgName = mysql_result($orgInfo, 0, 'orgName'); ?>
                <tr <?php if ($modAction == "new") {echo "class=new";} ?> >
                    <td></td>
                    <td></td>
                    <td><a href="modView.php?id=<?php echo $id; ?>&orgID=<?php echo $orgID; ?>" >New update request for <?php echo $orgName; ?></a></td>
                    <td><?php echo date("M d \a\\t h:ia ", $time_stamp); ?></td>
                    <td></td>
                </tr>
            <?php } ?>
            </tbody>
            <tfoot>
                <tr style="visibility:hidden">
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </tfoot>
        </table>
        <?php } ?>
		</div>
	</div>
<?php } ?>